package com.szh.taobaounion.ui.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.szh.taobaounion.model.domain.CateGories;
import com.szh.taobaounion.ui.fragment.HomePagerFragment;
import com.szh.taobaounion.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

public class HomePagerAdapter extends FragmentPagerAdapter {

    List<CateGories.DataBean>cateGoryList=new ArrayList<>();
    public HomePagerAdapter(@NonNull FragmentManager fm) {
        super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return cateGoryList.get(position).getTitle();

    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        LogUtils.d(this,"getItem---"+cateGoryList.get(position));
        CateGories.DataBean dataBean = cateGoryList.get(position);
        HomePagerFragment homePagerFragment = HomePagerFragment.newInstance(dataBean);
        return  homePagerFragment;
    }

    @Override
    public int getCount() {
        return cateGoryList.size();
    }

    public void setCategories(CateGories cateGories) {
        cateGoryList.clear();
        List<CateGories.DataBean> data = cateGories.getData();
        this.cateGoryList.addAll(data);
        LogUtils.d(this,"size"+cateGoryList.size());
        notifyDataSetChanged();
    }
}
